package com.settlement.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.settlement.system.common.util.common.DateUtil;
import com.settlement.system.common.util.common.FasUtil;
import com.settlement.system.common.util.common.SystemUserUtil;
import com.settlement.system.mapper.BaseMapper;
import com.settlement.system.mapper.TblNcVurcherNoRecordMapper;
import com.settlement.system.model.dto.NcVoucherNoDto;
import com.settlement.system.model.entity.common.SystemUser;
import com.settlement.system.model.entity.common.TblNcVurcherNoRecord;
import com.settlement.system.service.ITblNcVurcherNoRecordService;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * NC凭证明细-【操作记录】页签表 服务实现类
 *
 * @author hc
 * @since 2023-03-09
 */
@Service
public class TblNcVurcherNoRecordServiceImpl extends BaseServiceImpl implements ITblNcVurcherNoRecordService {

    @Resource
    private TblNcVurcherNoRecordMapper tblNcVurcherNoRecordMapper;

    @Override
    public BaseMapper init() {
        return tblNcVurcherNoRecordMapper;
    }

    @SneakyThrows
    @Override
    public NcVoucherNoDto saveRecord(Map<String, Object> params) {
        TblNcVurcherNoRecord record = new TblNcVurcherNoRecord();
        record.setId(String.valueOf(IdUtil.getSnowflake().nextId()));
        SystemUser systemUser = SystemUserUtil.getSystemUser();
        record.setCreateUser(systemUser.getUsername());
        record.setCreateTime(new Date());
        record.setActionType(1);
        record.setCompanyNames(FasUtil.parseInQueryCondition(MapUtils.getString(params, "companyNo")));
        record.setStatus(1);
        record.setAccountStatus(MapUtils.getInteger(params, "accountStatus"));
        record.setEditorStartDate(DateUtil.getDate(MapUtils.getString(params, "startOutDate")));
        record.setEditorEndDate(DateUtil.getDate(MapUtils.getString(params, "endOutDate")));
        tblNcVurcherNoRecordMapper.insert(record);
        NcVoucherNoDto dto = BeanUtil.toBean(params, NcVoucherNoDto.class);
        dto.setId(record.getId());
        return dto;
    }
}

